package com.flymobi.util;

import java.util.Date;

import com.flymobi.fw.modules.SM;
import com.flymobi.fw.modules.cache.CacheNeedsRefreshException;
import com.flymobi.fw.util.IDCreater;
import com.flymobi.vo.UserStateVo;

public class UserStateCacheUtil {
	public static final long SIZE = 10000;

	public static UserStateVo get(String userStateId) {
		UserStateVo userState = null;
		try {
			userState = (UserStateVo) SM.CacheOscache.getFromCache(
					C.CACHE.USER_STATE, userStateId,
					C.CACHE.USER_STATE_CACHETIME);
		} catch (CacheNeedsRefreshException e) {
			userState = new UserStateVo();
			userState.setId(IDCreater.nextId());
			userState.setQudaoId(0L);
			userState.setSavetime(new Date());
			save(userState);
		}
		if (userState == null) {

		}
		return userState;
	}

	public static void save(UserStateVo userState) {
		SM.CacheOscache.putInCache(C.CACHE.USER_STATE, userState.getId()+"",
				userState);
	}
}
